<template>
  <el-dialog :visible.sync="show" title="评分" width="450px">
    <el-row :gutter="24" class="pa_1">
      <el-col :span="6">
        <span>打分</span>
      </el-col>
      <el-col :span="18">
        <el-rate v-model="rate"></el-rate>
      </el-col>
    </el-row>
    <el-row class="pa_1">
      <el-col :span="6">
        <span>评论</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="comment"></el-input>
      </el-col>
    </el-row>
    <el-row slot="footer" class="frx">
      <el-button type="primary" @click="add" :disabled="!testSave()">保存</el-button>
    </el-row>
  </el-dialog>
</template>
<script>
import Aapi from "../../api/Advice.js";
export default {
  props: {
    visible: Boolean
  },
  data() {
    return {
      show: false,
      rate: 0,
      comment: ""
    };
  },
  watch: {
    visible: function(val) {
      if (val) {
        this.rate = 0;
        this.comment = "";
      }
      this.show = val;
    },
    show: function(val) {
      this.$emit("update:visible", val);
    }
  },
  methods: {
    add() {
      this.show = false;
      this.axios.post(Aapi.add,this.loadParams()).then(res => {
        if (res.data.status == 0) {
          this.$parent.loadSource();
        }
      });
    },
    loadParams() {
      return {
        username: this.$store.state.user.username,
        school: this.$store.state.user.school,
        suggest: this.comment,
        star: this.rate,
      };
    },
    testSave() {
      return this.comment != "" && this.rate >= 1;
    }
  }
};
</script>
<style>
</style>